package com.permission.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.permission.beans.PageQuery;
import com.permission.beans.PageResult;
import com.permission.common.JsonData;
import com.permission.entity.SysUser;
import com.permission.param.UserParam;
import com.permission.service.SysTreeService;
import com.permission.service.SysUserService;

import lombok.extern.slf4j.Slf4j;

/**
 * 部门Controller
 * @author jing
 *
 */
@Controller
@RequestMapping("/sys/user")
@Slf4j
public class SysUserController {
	
	@Autowired
    private SysUserService sysUserService;
	@Autowired
	private SysTreeService sysTreeService;
	
	/**
	 * 返回没有权限页面
	 */
	@RequestMapping("/noAuth.page")
    public ModelAndView noAuth() {
        return new ModelAndView("noAuth");
    }
	
	/**
	 * 增加用户
	 * @param param
	 * @return
	 */
	@RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveUser(UserParam param) {
        sysUserService.save(param);
        return JsonData.success();
    }
	
    /**
     * 更新用户
     * @param param
     * @return
     */
    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData updateUser(UserParam param) {
        sysUserService.update(param);
        return JsonData.success();
    }
	
    /**
     * 根据部门ID获取用户
     * @param deptId
     * @param pageQuery
     * @return
     */
    @RequestMapping("/page.json")
    @ResponseBody
    public JsonData page(@RequestParam("deptId") int deptId, PageQuery pageQuery) {
        PageResult<SysUser> result = sysUserService.getPageByDeptId(deptId, pageQuery);
        return JsonData.success(result);
    }
    
}
